package com.hyts.xmlparser.factory;

import com.hyts.xmlparser.convert.annotation.DefaultDateFieldConverter;
import com.hyts.xmlparser.convert.global.DateTimeConverter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.SingleValueConverter;

import java.util.Optional;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.xmlparser.factory
 * author:Libo/Alex
 * create-date:2019-07-18 13:51
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
public class XStreamFactory {

    /**
     * 转换器
     */
    private Converter converter;

    /**
     * 单值转换器
     */
    private SingleValueConverter singleValueConverter;


    /**
     * 构建工程对象
     * @return
     */
    public XStreamFactory start(){
        converter = null;
        singleValueConverter = null;
        return this;
    }

    /**
     * 创建对象实例
     * @return
     */
    public XStream end(){
        XStream xStream = new XStream();
        xStream.registerConverter(Optional.ofNullable(converter).orElse(new DateTimeConverter()));
        xStream.registerConverter(Optional.ofNullable(singleValueConverter).orElse(new DefaultDateFieldConverter()));
        return xStream;
    }
}
